var express = require('express')
var router = express.Router()
var User = require('./../models/User')
var md5 = require('blueimp-md5')
//* 匹配所有以api/login开头的url
router.post('*',(req,res) => {
    var body = req.body
    var telephone = body['params[telephone]']
    var password = body['params[password]']
    if(!telephone || !password) return res.json({status : -1})
    User.findOne({
        telephone : telephone,
        password : md5(md5(password))
    },function(err,docs){
        if(err) return res.json({status : -1})
        if(docs === null) return res.json({status : 1})
        //需要将当前用户存放到session中并将其存放到vuex中
        req.session.user = {
            nickname : docs.nickname
        }
        return res.json({status : 0, user : req.session.user})
    })
})

module.exports = router
